//
//  Risk.m
//  nova
//
//  Created by user on 11/05/29.
//  Copyright 2011 __MyCompanyName__. All rights reserved.
//

#import "Risk.h"

static UIImage *q1Image;
static UIImage *q2Image;
static UIImage *q3Image;
static UIImage *q4Image;
static UIImage *q5Image;


@implementation Risk

@synthesize risks;
@synthesize resourceList;

- (id) initWithRisks:(Risks *)rRisks {
    resourceList = [[NSMutableArray alloc] init];
    
    q1Image = [[UIImage imageNamed:@"nivel1.png"] retain];
    q2Image = [[UIImage imageNamed:@"nivel2.png"] retain];
    q3Image = [[UIImage imageNamed:@"nivel3.png"] retain];
    q4Image = [[UIImage imageNamed:@"nivel4.png"] retain];
    q5Image = [[UIImage imageNamed:@"nivel5.png"] retain];
    
    self = [super init];
    risks = rRisks;
    [self loadResources];
    
    
    return self;
}

- (void) loadResources{
	DataContext *context = [[DataContext alloc]init];
	[context getFromQueryToArrayResources:[risks getSelectStringForResources] : [risks colResources]];
	[context dealloc];
	for(Resources *p in [risks colResources])
	{
		Resource *resource = [[Resource alloc] initWithResources:p];
		[resourceList addObject:resource];
	}
    
    NSLog(@"Resources: %d", [resourceList count]);
}

- (NSString *) getCause {
    
    return  [risks vCause];
}

- (NSString *) getEffect {
    
    return  [risks vEffect];
}

- (int) getProbability {
    
    return  [risks vProbability];
}

- (int) getImpact {
    
    return  [risks vImpact];
}

- (int) getID {
    
    return  [risks vId_risks];
}

- (double) getMonitorFinish {
    
    return [risks vMonitoring_Finish];
}

- (double) getResponseFinish {
    
    return [risks vResponse_Finish];
}

- (NSString *) getResponse_Owner {
    
    if ([resourceList count] > 0) {
        return [[resourceList objectAtIndex:0] getName]; 
        
    }
    else
    {
        return @"";
    }   
}

+ (UIImage *) setImage:(int)value {
    
    switch (value) {
        case 1:
            return q1Image;
            break;
        case 2:
            return q2Image;
            break;
        case 3:
            return q3Image;
            break;
        case 4:
            return q4Image;
            break;
        case 5:
            return q5Image;
            break;            
        default:
            return nil;
            break;
    }
}

- (void) dealloc{
	[super dealloc];
}

@end
